//
//  RGInviteView.m
//  RedGrass
//
//  Created by wuyine on 2018/12/14.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "RGInviteView.h"

@interface RGInviteView()
@property (nonatomic,strong) NSString *nickName;
@property (nonatomic,strong) UILabel *despLabel;
@end

@implementation RGInviteView

- (instancetype)init {
    if (self = [super init]) {
        UIImageView *bg = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"二维码_bj")];
        bg.userInteractionEnabled = YES;
        [self addSubview:bg];
        [bg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsZero);
        }];
        
        UIImageView *head = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"分享有礼_图案")];
        [bg addSubview:head];
        [head mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.trailing.mas_equalTo(0);
            make.top.mas_equalTo(KIsiPhoneX?44:22);
            make.height.mas_equalTo(KScreenWidth*490/375);
        }];
        
        [head addSubview:self.despLabel];
        [_despLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.bottom.mas_equalTo(-10);
        }];
        
        UILabel *tip = [[UILabel alloc] init];
        tip.textColor = [UIColor whiteColor];
        tip.text = @"好友注册后你将获得5元现金红包";
        tip.font = FONT(customFontName, 14);
        [bg addSubview:tip];
        [tip mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.equalTo(head.mas_bottom).offset(20);
        }];
        
        UIButton *wechat = [UIButton buttonWithType:UIButtonTypeCustom];
        [wechat setTitle:@"微信" forState:UIControlStateNormal];
        [wechat setTitleColor:UICOLOR_WITH_RGBINT(0xffffff) forState:UIControlStateNormal];
        [wechat setImage:IMAGE_NAMED(@"微信") forState:UIControlStateNormal];
        wechat.titleLabel.font = FONT(customFontName, 14);
        // button标题的偏移量
        wechat.titleEdgeInsets = UIEdgeInsetsMake(wechat.currentImage.size.height+5, -wechat.currentImage.size.width, 0,0);
        // button图片的偏移量
        wechat.imageEdgeInsets = UIEdgeInsetsMake(0,15,25,-15);
        [wechat addTarget:self action:@selector(shareToWechat:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *circle = [UIButton buttonWithType:UIButtonTypeCustom];
        [circle setTitle:@"朋友圈" forState:UIControlStateNormal];
        [circle setTitleColor:UICOLOR_WITH_RGBINT(0xffffff) forState:UIControlStateNormal];
        [circle setImage:IMAGE_NAMED(@"朋友圈") forState:UIControlStateNormal];
        circle.titleLabel.font = FONT(customFontName, 14);
        // button标题的偏移量
        circle.titleEdgeInsets = UIEdgeInsetsMake(circle.currentImage.size.height+5, -circle.currentImage.size.width, 0,0);
        // button图片的偏移量
        circle.imageEdgeInsets = UIEdgeInsetsMake(0,15,25,-25);
        [circle addTarget:self action:@selector(shareToCircle:) forControlEvents:UIControlEventTouchUpInside];
        
        [bg addSubview:wechat];
        [bg addSubview:circle];
        [wechat mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(-60);
            make.size.mas_equalTo(CGSizeMake(100, 100));
            make.top.equalTo(tip.mas_bottom).offset(30);
        }];
        [circle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(60);
            make.size.mas_equalTo(CGSizeMake(100, 100));
            make.top.equalTo(tip.mas_bottom).offset(30);
        }];
        
        UIView *line = [[UIView alloc] init];
        line.backgroundColor = UICOLOR_WITH_RGBINT(0xcccccc);
        [bg addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.trailing.mas_equalTo(0);
            make.height.mas_equalTo(0.5);
            make.bottom.mas_equalTo(-44+(KIsiPhoneX?-34:0));
        }];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:@"取消" forState:UIControlStateNormal];
        btn.titleLabel.textColor = [UIColor whiteColor];
        btn.titleLabel.font = FONT(customFontName, 14);
        [btn addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
        [bg addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(KIsiPhoneX?-34:0);
            make.leading.trailing.mas_equalTo(0);
            make.height.mas_equalTo(44);
        }];
    }
    return self;
}

- (void)shareToWechat:(UIGestureRecognizer *)recog {
    
}

- (void)shareToCircle:(UIGestureRecognizer *)recog {
    
}

- (void)showInView:(UIView *)view {
    [view addSubview:self];
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
}

- (void)cancel:(UIButton *)btn {
    [self removeFromSuperview];
}

- (UILabel *)despLabel {
    if (!_despLabel) {
        _despLabel = [[UILabel alloc] init];
        _despLabel.numberOfLines = 0;
        _despLabel.textAlignment = NSTextAlignmentCenter;
        _despLabel.textColor = UICOLOR_WITH_RGBINT(0x000000);
        _despLabel.font = FONT(@"PingFangSC-Semibold", 16);
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"我是%@\n我在红草视界发现了好多好玩的视频\n忍不住把它推荐给你\n快来和我一起玩吧~",_nickName]];
        [str addAttribute:NSFontAttributeName value:FONT(@"PingFangSC-Semibold", 17) range:NSMakeRange(2, _nickName.length)];
        _despLabel.attributedText = str;
        
    }
    return _despLabel;
}

@end
